Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inner sum in BGV #513

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

lehugueni
Copy link
Contributor

@lehugueni lehugueni commented Nov 20, 2024

Refactor of the inner sum API in lattigo. Fixes #510.

Issue

bgv.Evaluator.InnerSum was not working properly when n*batchSize = N (where N is the number of slots) as InnerSum was acting separately on the "rows" of the underlying plaintext.

It has been decided to refactor the whole InnerSum API in lattigo to be more coherent.

Changes

  • Refactoring of the InnerSum methods:
    • rlwe.Evaluator.InnerSum has been replaced by rlwe.Evaluator.PartialTrace to reflect that at the level of rlwe the notion of inner sum does not exist.
    • Introduction of the bgv.Evaluator.InnerSum and ckks.Evaluator.InnerSum methods, which have the same behaviour as the old InnerSum method for parameters n and batchSize s.t. 0 < n*batchSize <= ctIn.Slots() divides the number of slots. Parameters not satisfying these conditions are rejected.
    • Introduction of the bgv.Evaluator.RotateAndAdd and ckks.Evaluator.RotateAndAdd methods, which have the same behaviour as the old InnerSum method for all parameters.
  • New tests have been added.

In summary, #510 is fixed, legacy code is still supported except when n*batchSize does not divide the number of slots (or if n*batchSize is not in the interval [1, ctIn.Slots()]). In that case, RotateAndAdd must be used.

@lehugueni lehugueni added the bug Something isn't working label Nov 20, 2024
@lehugueni lehugueni self-assigned this Nov 20, 2024
schemes/bgv/evaluator.go Outdated Show resolved Hide resolved
schemes/bgv/evaluator.go Show resolved Hide resolved
schemes/bgv/evaluator.go Outdated Show resolved Hide resolved
schemes/bgv/evaluator.go Show resolved Hide resolved
schemes/bgv/params.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Pro7ech Pro7ech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename rlwe.Evaluator.PartialTrace to rlwe.Evaluator.PartialTracesSum or something similar because here we have an accumulator accQP that sums HW(n) partial traces. It's only when n is a power of two (where HW(n) = 1) and offset divides n that we have a true partial Trace (in the sens that full trace is from 0 to LogN and partial means from a to b where 0<= a < b <= logN). In other words, .Trace is a special case of PartialTracesSum.

Else I'm happy with the proposed solution.

Copy link

@MGeorgie MGeorgie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this solution

CHANGELOG.md Outdated Show resolved Hide resolved
@lehugueni
Copy link
Contributor Author

lehugueni commented Dec 18, 2024

I would rename rlwe.Evaluator.PartialTrace to rlwe.Evaluator.PartialTracesSum or something similar because here we have an accumulator accQP that sums HW(n) partial traces. It's only when n is a power of two (where HW(n) = 1) and offset divides n that we have a true partial Trace (in the sens that full trace is from 0 to LogN and partial means from a to b where 0<= a < b <= logN). In other words, .Trace is a special case of PartialTracesSum.

Yes I agree, it is a partial trace in the sense that it is a sum with a subset of the automorphisms, but you're right that Trace can also be partial in that sense. I've changed to PartialTracesSum for now, we can rename it at a later time if someone finds a better suited name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug/Regression [BGV]: Wrong result from innerSum for params.N() elements
3 participants